package com.woniuxy.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.woniuxy.DTO.AlgsDisinfectRecordDTO;
import com.woniuxy.DTO.AlgsFeedingRecordDTO;
import com.woniuxy.domain.AlgsFeedingRecord;
import com.woniuxy.service.IAlgsTypeService;
import com.woniuxy.vo.AlgsDisinfectRecordVO;
import com.woniuxy.vo.AlgsFeedingRecirdVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniuxy.domain.AlgsDisinfectionRecord;
import com.woniuxy.service.IAlgsDisinfectionRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * @author ：张宇
 * @date ：Created in 2023-03-16 19:33
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
@RequestMapping("/disinfect")
public class AlgsDisinfectionRecordController extends BaseController {
    @Autowired
    private IAlgsDisinfectionRecordService algsDisinfectionRecordService;
@Resource
private IAlgsTypeService iAlgsTypeService;
    /**
     * 查询消毒记录列表
     */
   // @RequiresPermissions("disinfect:disinfect:list")
    @GetMapping("/list")
    public TableDataInfo list(AlgsDisinfectRecordDTO algsDisinfectRecordDTO) {
        startPage();
        List<AlgsDisinfectRecordVO> list = algsDisinfectionRecordService.queryAlgsDisinfectionRecordAndTypeMsgAndStaffName(algsDisinfectRecordDTO);
        return getDataTable(list);
    }

    /**
     * 导出消毒记录列表
     */
    //@RequiresPermissions("disinfect:disinfect:export")
    @Log(title = "消毒记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsDisinfectionRecord algsDisinfectionRecord) {
        List<AlgsDisinfectionRecord> list = algsDisinfectionRecordService.selectAlgsDisinfectionRecordList(algsDisinfectionRecord);
        ExcelUtil<AlgsDisinfectionRecord> util = new ExcelUtil<AlgsDisinfectionRecord>(AlgsDisinfectionRecord.class);
        util.exportExcel(response, list, "消毒记录数据");
    }



    /**
     * 新增消毒记录
     */
    //@RequiresPermissions("disinfect:disinfect:add")
    @Log(title = "消毒记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgsDisinfectionRecord algsDisinfectionRecord) {
        return toAjax(algsDisinfectionRecordService.insertAlgsDisinfectionRecord(algsDisinfectionRecord));
    }

    /**
     * 修改消毒记录(记录不能修改)
     */
    //@RequiresPermissions("disinfect:disinfect:edit")

    /**
     * 查询所有的消毒状态（员工）
     */
    @GetMapping("/queryTypeDisinfect")
    public AjaxResult queryTypeDisinfect()
    {
        return success(iAlgsTypeService.selectAllDisinfectTypeMsg());
    }

    /**
     * 提交消毒记录
     */
    @GetMapping( "DisinfectionEMP{disinfectionRecordId}")
        public AjaxResult getDisinfectionEMP(@PathVariable("disinfectionRecordId") Long disinfectionRecordId)
    {
        System.out.println(disinfectionRecordId);
        AlgsDisinfectionRecord algsDisinfectionRecord = new AlgsDisinfectionRecord();
        algsDisinfectionRecord.setTypeId(68L);
        algsDisinfectionRecord.setDisinfectionRecordId(disinfectionRecordId);
        return success(algsDisinfectionRecordService.updateAlgsDisinfectionRecord(algsDisinfectionRecord));
    }
    /**
     * 查询全部消毒状态(管理)
     */
    @GetMapping("/listManager")

    public TableDataInfo listDisinfectManager(AlgsDisinfectRecordDTO algsDisinfectRecordDTO){
        startPage();
        List<AlgsDisinfectRecordVO> list = algsDisinfectionRecordService.queryAlgsDisinfectionRecordAndTypeMsgAndStaffNameManager(algsDisinfectRecordDTO);
        return getDataTable(list);
    }
    /**
     * 管理员已读消毒记录
     */
    @GetMapping( "DisinfectionManager{disinfectionRecordId}")
    public AjaxResult getDisinfectionRecordManager(@PathVariable("disinfectionRecordId") Long disinfectionRecordId)
    {

        AlgsDisinfectionRecord algsDisinfectionRecord = new AlgsDisinfectionRecord();
        algsDisinfectionRecord.setTypeId(69L);
        algsDisinfectionRecord.setDisinfectionRecordId(disinfectionRecordId);
        return success(algsDisinfectionRecordService.updateAlgsDisinfectionRecord(algsDisinfectionRecord));
    }
    /**
     * 管理员归档消毒记录
     */
    @GetMapping( "delDisinfectionManager{disinfectionRecordId}")
    public AjaxResult delDisinfectionRecordManager(@PathVariable("disinfectionRecordId") Long disinfectionRecordId)
    {
        System.out.println(disinfectionRecordId);
        AlgsDisinfectionRecord algsDisinfectionRecord = new AlgsDisinfectionRecord();
        algsDisinfectionRecord.setTypeId(70L);
        algsDisinfectionRecord.setDisinfectionRecordId(disinfectionRecordId);
        return success(algsDisinfectionRecordService.updateAlgsDisinfectionRecord(algsDisinfectionRecord));
    }
}